import { _decorator, Component, Node, Vec3, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('HexagonJenga_grid')
export class HexagonJenga_grid extends Component {
    /** 类型 */
    public kind: number = 1;
    /** 排序索引 */
    public index: number = 0;
    /** 分组索引 */
    public sortIndex: number = 0;
    public posIndex: number = -1;
    /** 网格中的横向位置 */
    public hor: number = -1;
    public ver: number = -1;

    onLoad() {
    }

    setKind(kind: number) {
        this.kind = kind;
        this.node.children.forEach(item => {
            item.active = +item.name.substring(item.name.length - 1, item.name.length) == kind;
        });
        this.node.getChildByName('lb').active = false;
        // CocosHelper.updateLabelText(this.node.getChildByName('lb'), kind);
    }

    /** 放入网格中后才会设置 */
    setHorVer(hor: number, ver: number) {
        this.hor = hor;
        this.ver = ver;
    }

    showSib(num: number) {
        // CocosHelper.updateLabelText(this.node.getChildByName("lb"), num);
    }

    setIdx(sortIndex: number, idx: number, posIdx: number = -1) {
        this.posIndex = posIdx;
        this.sortIndex = sortIndex;
        this.index = idx;
        // CocosHelper.updateLabelText(this.node.getChildByName("lb"), sortIndex + "-" + idx);
    }

    isClickInside(pos: Vec3) {
        /** 已经在网格中了就不能移动了 */
        if (this.hor >= 0) return false;
        let width = this.node.getComponent(UITransform).width;
        let height = this.node.getComponent(UITransform).height;
        let curPos = this.node.position;
        if (Math.abs(pos.x - curPos.x) <= width / 2 && Math.abs(pos.y - curPos.y) <= height / 2) return true;
        return false;
    }
}